\newcommand{\RisultatoUnoNoPreempion}{%
\begin{tikzpicture}[
  yscale = 0.8,
  normal/.style={ fill=black!30},
  resource/.style={ fill=black!80},
  waiting/.style={fill=white},
  busywait/.style={fill=black!10, postaction={pattern=north east lines, very thin}},
  release/.style={-latex},
  request/.style={-o},
  complet/.style={-|},
  every text node part/.style={align=center}
]
%general params
\def\th{.4} %task height
\def\tyDown{0} %task a asse y
\def\tyUp{1}
\def\blockdim{(.4,.4)}
\def\arrowdim{(0,.5)}
\def\arrowdimB{(0,.4)}
\coordinate (legend) at (1,2.5);

%tasklines
\draw[thin, gray] (-.7,\tyDown)node[above,left,black]{$P_2$} -- +(12.2,0);
\draw[thin, gray] (-.7,\tyUp)node[above,left,black]{$P_1$} -- +(12.2,0);

%axes
\draw[thick, black, -] (-.5,-1) -- (-.5, 3.3);
\draw[thick, black, ->] (-1,-.5) -- (12, -.5) node[below] {{\footnotesize time}};

\draw[thick, black, -] (0,-.65) -- (0, -0.35);
\draw[thick, black, -] (2,-.65) -- (2, -0.35);
\draw[thick, black, -] (4,-.65) -- (4, -0.35);
\draw[thick, black, -] (6,-.65) -- (6, -0.35);
\draw[thick, black, -] (8,-.65) -- (8, -0.35);
\draw[thick, black, -] (10,-.65) -- (10, -0.35);

\path(0,-.6)node[below]{{\footnotesize $t$}};
\path(4,-.6)node[below]{{\footnotesize $t + 1 ms$}};
\path(8,-.6)node[below]{{\footnotesize $t + 2 ms$}};

%L1
\draw[release] (0,   \tyUp) -- +(0,0.8);
\draw[normal]  (0,   \tyUp) rectangle +(0.5, \th) node[midway] {{\footnotesize $L_1$}};
\draw[request] (0.5,\tyUp) -- +(0,0.8);
\draw[resource]  (0.5,   \tyUp) rectangle +(4, \th) node[midway,color=white] {{\footnotesize $L_1$}};;

%H2
\draw[release] (1,   \tyUp) -- +(0,0.8) node[above] {{\tiny $H_2$}};
\draw[normal]  (4.5,   \tyUp) rectangle +(4, \th) node[midway] {{\footnotesize $H_2$}};
\draw[complet] (8.5,\tyUp) -- +(0, 0.8);

%L1

\draw[normal]  (8.5,   \tyUp) rectangle +(0.5, \th) node[midway] {{\footnotesize $L_1$}};
\draw[complet] (9,\tyUp) -- +(0, 0.8);

%L3
\draw[release] (0.2,   \tyDown) -- +(0,0.8);
\draw[normal]  (0.2,   \tyDown) rectangle +(0.5, \th) node[midway] {{\footnotesize $L_3$}};
\draw[request] (0.7,\tyDown) -- +(0,0.8);
\fill[busywait] (0.7, \tyDown) rectangle +(3.8, \th) node[midway] {{\footnotesize $L_3$}};

\draw[resource]  (4.5,   \tyDown) rectangle +(4, \th) node[midway,color=white] {{\footnotesize $L_3$}};
\draw[normal]  (8.5,   \tyDown) rectangle +(0.5, \th) node[midway] {{\footnotesize $L_3$}};
\draw[complet] (19,\tyDown) -- +(0, 0.8);


\draw[thick, red, dashed, -] (1,-0.7) -- (1, 2);
\draw[thick, red, <->] (1,.70) -- (4.5, .70) node[midway, fill=white, xshift=-1.75] {{\scriptsize \textbf{Block}}};
\draw[thick, red, dashed, -] (4.5,-0.7) -- (4.5, 2);

\draw[normal]   ($(   0,0.5) + (legend)$) node[below, xshift=0.2cm]{\tiny executing} rectangle +\blockdim;
\draw[resource] ($(1.75,0.5) + (legend)$) node[below, xshift=0.2cm]{\tiny resource} rectangle +\blockdim;
\fill[busywait] ($( 3.5,0.5) + (legend)$) node[below, xshift=0.2cm]{\tiny busy wait} rectangle +\blockdim;
\draw[release]  ($(5.25,0.5) + (legend)$) node[below]{\tiny job release}      -- +\arrowdim;
\draw[request]  ($(   7,0.5) + (legend)$) node[below]{\tiny request}     -- +\arrowdim;
\draw[complet]  ($(8.75,0.5) + (legend)$) node[below]{\tiny completion}   -- +\arrowdimB;

\end{tikzpicture}
}

\newcommand{\RisultatoUnoCeiling}{%
\begin{tikzpicture}[
  yscale = 0.8,
  normal/.style={ fill=black!30},
  resource/.style={ fill=black!80},
  waiting/.style={fill=white},
  busywait/.style={fill=black!10, postaction={pattern=north east lines, very thin}},
  release/.style={-latex},
  request/.style={-o},
  complet/.style={-|},
  every text node part/.style={align=center}
]
%general params
\def\th{.4} %task height
\def\tyDown{0} %task a asse y
\def\tyUp{1}
\def\blockdim{(.4,.4)}
\def\arrowdim{(0,.5)}
\def\arrowdimB{(0,.4)}
\coordinate (legend) at (1,2.5);

%tasklines
\draw[thin, gray] (-.7,\tyDown)node[above,left,black]{$P_2$} -- +(14,0);
\draw[thin, gray] (-.7,\tyUp)node[above,left,black]{$P_1$} -- +(14,0);

%axes
\draw[thick, black, -] (-.5,-1) -- (-.5, 3.3);
\draw[thick, black, ->] (-1,-.5) -- (13.5, -.5) node[below] {{\footnotesize time}};

\draw[thick, black, -] (0,-.65) -- (0, -0.35);
\draw[thick, black, -] (2,-.65) -- (2, -0.35);
\draw[thick, black, -] (4,-.65) -- (4, -0.35);
\draw[thick, black, -] (6,-.65) -- (6, -0.35);
\draw[thick, black, -] (8,-.65) -- (8, -0.35);
\draw[thick, black, -] (10,-.65) -- (10, -0.35);
\draw[thick, black, -] (12,-.65) -- (12, -0.35);

\path(0,-.6)node[below]{{\footnotesize $t$}};
\path(4,-.6)node[below]{{\footnotesize $t + 1 ms$}};
\path(8,-.6)node[below]{{\footnotesize $t + 2 ms$}};
\path(12,-.6)node[below]{{\footnotesize $t + 3 ms$}};


%L1
\draw[release] (0,   \tyUp) -- +(0,0.8);
\draw[normal]  (0,   \tyUp) rectangle +(0.5, \th) node[midway] {{\footnotesize $L_1$}};
\draw[request] (0.5,\tyUp) -- +(0,0.8);
\draw[resource]  (0.5,   \tyUp) rectangle +(0.5, \th) node[midway,color=white] {{\footnotesize $L_1$}};;

%H2
\draw[release] (1,   \tyUp) -- +(0,0.8);
\draw[normal]  (1,   \tyUp) rectangle +(4, \th) node[midway] {{\footnotesize $H_2$}};
\draw[complet] (5,\tyUp) -- +(0, 0.8);

%L1

\draw[resource]  (5,   \tyUp) rectangle +(3.5, \th) node[midway,color=white] {{\footnotesize $L_1$}};;
\draw[normal]  (8.5,   \tyUp) rectangle +(0.5, \th) node[midway] {{\footnotesize $L_1$}};
\draw[complet] (9,\tyUp) -- +(0, 0.8);

%L3
\draw[release] (0.2,   \tyDown) -- +(0,0.8);
\draw[normal]  (0.2,   \tyDown) rectangle +(0.5, \th) node[midway] {{\footnotesize $L_3$}};
\draw[request] (0.7,\tyDown) -- +(0,0.8);
\fill[busywait] (0.7, \tyDown) rectangle +(7.8, \th) node[midway] {{\footnotesize $L_3$}};

\draw[resource]  (8.5,   \tyDown) rectangle +(4, \th) node[midway,color=white] {{\footnotesize $L_3$}};
\draw[normal]  (12.5,   \tyDown) rectangle +(0.5, \th) node[midway] {{\footnotesize $L_3$}};
\draw[complet] (13,\tyDown) -- +(0, 0.8);


\draw[thick, red, dashed, -] (1,-0.7) -- (1, 2);
\draw[thick, red, <->] (1,.70) -- (5, .70) node[midway, fill=white, xshift=-1.75] {{\scriptsize \textbf{Interference}}};
\draw[thick, red, dashed, -] (5,-0.7) -- (5, 2);

\draw[normal]   ($(   0,0.5) + (legend)$) node[below, xshift=0.2cm]{\tiny executing} rectangle +\blockdim;
\draw[resource] ($(1.75,0.5) + (legend)$) node[below, xshift=0.2cm]{\tiny resource} rectangle +\blockdim;
\fill[busywait] ($( 3.5,0.5) + (legend)$) node[below, xshift=0.2cm]{\tiny busy wait} rectangle +\blockdim;
\draw[release]  ($(5.25,0.5) + (legend)$) node[below]{\tiny job release}      -- +\arrowdim;
\draw[request]  ($(   7,0.5) + (legend)$) node[below]{\tiny request}     -- +\arrowdim;
\draw[complet]  ($(8.75,0.5) + (legend)$) node[below]{\tiny completion}   -- +\arrowdimB;

\end{tikzpicture}
}

\newcommand{\RisultatoUnoMrsP}{%
\begin{tikzpicture}[
  yscale = 0.8,
  normal/.style={ fill=black!30},
  resource/.style={ fill=black!80},
  waiting/.style={fill=white},
  busywait/.style={fill=black!10, postaction={pattern=north east lines, very thin}},
  release/.style={-latex},
  request/.style={-o},
  complet/.style={-|},
  every text node part/.style={align=center}
]
%general params
\def\th{.4} %task height
\def\tyDown{0} %task a asse y
\def\tyUp{1}
\def\blockdim{(.4,.4)}
\def\arrowdim{(0,.5)}
\def\arrowdimB{(0,.4)}
\coordinate (legend) at (1,2.5);

%tasklines
\draw[thin, gray] (-.7,\tyDown)node[above,left,black]{$P_2$} -- +(12.2,0);
\draw[thin, gray] (-.7,\tyUp)node[above,left,black]{$P_1$} -- +(12.2,0);

%axes
\draw[thick, black, -] (-.5,-1) -- (-.5, 3.3);
\draw[thick, black, ->] (-1,-.5) -- (12, -.5) node[below] {{\footnotesize time}};

\draw[thick, black, -] (0,-.65) -- (0, -0.35);
\draw[thick, black, -] (2,-.65) -- (2, -0.35);
\draw[thick, black, -] (4,-.65) -- (4, -0.35);
\draw[thick, black, -] (6,-.65) -- (6, -0.35);
\draw[thick, black, -] (8,-.65) -- (8, -0.35);
\draw[thick, black, -] (10,-.65) -- (10, -0.35);

\path(0,-.6)node[below]{{\footnotesize $t$}};
\path(4,-.6)node[below]{{\footnotesize $t + 1 ms$}};
\path(8,-.6)node[below]{{\footnotesize $t + 2 ms$}};

%L1
\draw[release] (0,   \tyUp) -- +(0,0.8);
\draw[normal]  (0,   \tyUp) rectangle +(0.5, \th) node[midway] {{\footnotesize $L_1$}};
\draw[request] (0.5,\tyUp) -- +(0,0.8);
\draw[resource]  (0.5,   \tyUp) rectangle +(0.5, \th) node[midway,color=white] {{\footnotesize $L_1$}};;

%H2
\draw[release] (1,   \tyUp) -- +(0,0.8);
\draw[normal]  (1,   \tyUp) rectangle +(4, \th) node[midway] {{\footnotesize $H_2$}};
\draw[complet] (5,\tyUp) -- +(0, 0.8);

%L3
\draw[release] (0.2,   \tyDown) -- +(0,0.8);
\draw[normal]  (0.2,   \tyDown) rectangle +(0.5, \th) node[midway] {{\footnotesize $L_3$}};
\draw[request] (0.7,\tyDown) -- +(0,0.8);
\fill[busywait] (0.7, \tyDown) rectangle +(0.6, \th) node[midway] {{\footnotesize $L_3$}};

%L1

\draw[resource]  (1.3,   \tyDown) rectangle +(3.5, \th) node[midway,color=white] {{\footnotesize $L_1$}};;

%L3

\draw[resource]  (4.8,   \tyDown) rectangle +(4, \th) node[midway,color=white] {{\footnotesize $L_3$}};
\draw[normal]  (8.8,   \tyDown) rectangle +(0.5, \th) node[midway] {{\footnotesize $L_3$}};
\draw[complet] (9.3,\tyDown) -- +(0, 0.8);

% L1

\draw[normal]  (5,   \tyUp) rectangle +(0.5, \th) node[midway] {{\footnotesize $L_1$}};
\draw[complet] (5.5,\tyUp) -- +(0, 0.8);

\draw[thick, red, dashed, -] (1,-0.7) -- (1, 2);
\draw[thick, red, |-|] (1,.70) -- (1.3, .70) node[right, fill=white, xshift=1.75] {{\tiny \textbf{Migration}}};
\draw[thick, red, dashed, -] (1.3,-0.7) -- (1.3, 2);

\draw[normal]   ($(   0,0.5) + (legend)$) node[below, xshift=0.2cm]{\tiny executing} rectangle +\blockdim;
\draw[resource] ($(1.75,0.5) + (legend)$) node[below, xshift=0.2cm]{\tiny resource} rectangle +\blockdim;
\fill[busywait] ($( 3.5,0.5) + (legend)$) node[below, xshift=0.2cm]{\tiny busy wait} rectangle +\blockdim;
\draw[release]  ($(5.25,0.5) + (legend)$) node[below]{\tiny job release}      -- +\arrowdim;
\draw[request]  ($(   7,0.5) + (legend)$) node[below]{\tiny request}     -- +\arrowdim;
\draw[complet]  ($(8.75,0.5) + (legend)$) node[below]{\tiny completion}   -- +\arrowdimB;

\end{tikzpicture}
}